package com.example.leero.graduation.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.example.leero.graduation.R;
import com.example.leero.graduation.Util.DateUtil;
import com.example.leero.graduation.Util.ImageLoader;
import com.example.leero.graduation.Util.StringUtil;
import com.example.leero.graduation.activity.DetailActivity;
import com.example.leero.graduation.model.MineAct;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by Leero on 2017-6-3.
 */

public class ActUserPublishAdapter extends CommonAdapter<MineAct> {

    private Context mContext;

    public ActUserPublishAdapter(Context context, int layoutId, List<MineAct> datas) {
        super(context, layoutId, datas);
        this.mContext = context;
    }

    @Override
    protected void convert(ViewHolder holder, final MineAct mineAct, int position) {
        ImageView avatar = holder.getView(R.id.iv_avatar);
        if (!StringUtil.isEmpty(mineAct.avatar)) {
            ImageLoader.load(mContext, avatar, mineAct.avatar);
        } else {
            avatar.setImageResource(R.drawable.default_avatar_cricle);
        }

        // 0:女  1:男
        ImageView sex = holder.getView(R.id.iv_sex);
        if (mineAct.sex == 0) {
            sex.setImageResource(R.drawable.draw_women);
        } else {
            sex.setImageResource(R.drawable.draw_man);
        }

        holder.setText(R.id.tv_nickname, mineAct.user_name);
        holder.setText(R.id.tv_time, DateUtil.getDateStringFromTZ(mineAct.time));
        holder.setText(R.id.tv_title, mineAct.title);

        holder.setOnClickListener(R.id.item_root, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, DetailActivity.class);
                intent.putExtra("id", mineAct.id);
                mContext.startActivity(intent);
            }
        });
    }
}
